package sk.talker.atlantis.icefaces.beans;

public class TalkerTelnetBean {
	
	TalkerInputBean talkerInputBean;
	TalkerOutputBean talkerOutputBean;
	TalkerLoginBean talkerLoginBean;
	
	TalkerTelnetClient talkerTelnetClient;
	
	String username;
	
	public TalkerTelnetBean() {
		talkerInputBean = new TalkerInputBean();
		talkerOutputBean = new TalkerOutputBean();
		talkerLoginBean = new TalkerLoginBean();
		
		talkerTelnetClient = new TalkerTelnetClient();
	}
	
	public String login() {
		String username = talkerLoginBean.getLoginUsername();
		String password = talkerLoginBean.getLoginPassword();
		return login(username, password);
	}
	
	private String login(String username, String password) {
		//TODO popripade sa posle nieco ine ako outcome.. (boolean, String/null).. napr .who alebo nejaka ina informacia
		String outcome = talkerTelnetClient.connect(username, password);
		if (outcome.equals("success")) {
			this.username = username;
			return "success";
		}
		else {
			return "failure";
		}
	}
	
	public String read() {
		return talkerTelnetClient.read();
	}
	
}
